home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / amos / amoslist-0295.lzh / AMOSLIST / text0196.txt < prev    next >
Encoding:
Text File  |  1995-03-01  |  12.5 KB  |  949 lines

  1. Well, I was bored, so I cooked up the bare bones for a text adventure 
  2. game.  It may not look pretty, but what's here works so far.  Here's a 
  3. breakdown of the variables and procedures...
  4.  
  5. NW    Number of words per command (max).
  6. W$()    Holds command and its parameters.  W$(1) is the command,
  7.     and W$(2) is its first parameter.  A "###" in an element
  8.     means that there are no more parameters to follow.
  9. RD$()    Holds room descriptions.
  10. OB$()    Holds object descriptions.  OB$(x,0) is the object's name,
  11.     OB$(x,1) is it's description for EXAMINE[], and OB$(x,2) is
  12.     reserved for future expansion.
  13. OB()    Holds object information.  OB(x,0) is the room that the object
  14.     is in.  A 0 indicates that the player is holding the object.  The
  15.     other elements are unused, but are for things like score, weight,
  16.     and special attributes.
  17. RM()    Holds room information.  RM(x,0) contains the number of objects in
  18.     a room.  RM(x,1) to RM(x,10) indicate which rooms are accessible
  19.     in which direction.  (See D$())
  20. D$()    Directions corresponiding to RM(x,1) - RM(x,10).
  21. DD$()    Abbreviations of directions for moving.
  22. CD$    Moves the cursor to the left of the screen and down one line for
  23.     formatting data strings.
  24.  
  25. BRKSENTENCE[]    Breaks A$ down into words and stores them in W$().
  26. SROOM[]        Displays current room, showing exits and objects.
  27. CMD[]    Displays a prompt and reads a command.  If a null is entered
  28.     a "Huh?" is displayed, and if the word "again" is entered, it
  29.     repeats the last command (passed as a parameter).  The command
  30.     is returned in Param$.
  31. TAKE    Picks up objects and stores in player's inventory.  Objects can be
  32.     specified as "all" (picks up all objects in current room) or as a
  33.     list (with "and" and "the" being ignored).
  34. DROP    The antithesis to TAKE.
  35. INV    Displays the player's inventory.
  36. EXAMINE        Allows the player to examine an object if they are holding
  37.     it.  If the object is not held by the player but is in the room,
  38.     a message will be displayed telling them to pick it up.  If the
  39.     object isn't in the room, it tells you there isn't one.
  40. HELP    Hah!
  41. TME    Displays the game time.  Each turn takes a "minute" excluding
  42.     invalid commands.
  43. DUMP    A debugging aid - displays the contents of W$().
  44.  
  45. Current commands:
  46.  
  47. n, s, e, w, ne, se, nw, sw, up, down : Move in the desired direction.
  48. get, take : Pick up objects.
  49. time : Show game time.
  50. help : Display a sarcastic message.
  51. drop : Drop objects.
  52. quit : Exit game.
  53. again : Repeat last command.
  54. look : Show room description, exits, and objects.
  55. inv, inventory : Show objects held by player.
  56. exam, examine : Look closely at an object.
  57.  
  58. I'm working on containers (objects which can contain other objects), and 
  59. functions for helping plot development, like DOES_HOLD, HAS_HELD, 
  60. HAS_BEEN_TO, IS_IN, etc., plus things like automapping, et al.  I also 
  61. may turn it into an adventure creator, but that looks like hard work. :)  
  62. (I'm also working on a multi-player version for people running TCP/IP, 
  63. but I'm not even going to ATTEMPT that in AMOS - that's a job for C! :)  
  64. Anyone recommend a decent PD or shareware C compiler?  I'm using an 
  65. ancient version of DICE at the moment....
  66.  
  67. Anyway, here it is - sorry for the length of my posting and rambling, but 
  68. it's been a slow day at work. :)
  69.  
  70. (Oh, and I had to post raw ASCII 'cause I'm on a (hack, cough) PC at the 
  71. moment.)
  72.  
  73. ********************************
  74. Set Buffer 100
  75.  
  76. Screen Open 0,640,200,4,Hires
  77.  
  78.  
  79.  
  80.  
  81.  
  82. NW=20
  83.  
  84.  
  85.  
  86. Dim W$(NW)
  87.  
  88. Global W$()
  89.  
  90.  
  91.  
  92. Dim RD$(64),OB$(256,2),OB(256,10),RM(64,15),D$(10)
  93.  
  94. Global RD$(),OB$(),OB(),RM(),D$(),NW,TM
  95.  
  96. Dim DD$(10)
  97.  
  98. NAMEO=0
  99.  
  100. DESCO=1
  101.  
  102. NUMOB=0
  103.  
  104. CURRM=1
  105.  
  106. OBRM=0
  107.  
  108.  
  109.  
  110. For OO=0 To 256
  111.  
  112.    OB(OO,0)=-1
  113.  
  114. Next 
  115.  
  116.  
  117.  
  118. Global NAMEO,DESCO,NUMOB,CURRM,CD$,OBRM
  119.  
  120. CD$=Chr$(27)+"X"+Chr$(48)+Cdown$
  121.  
  122.  
  123.  
  124. D$(1)="north"
  125.  
  126. D$(2)="south"
  127.  
  128. D$(3)="east"
  129.  
  130. D$(4)="west"
  131.  
  132. D$(5)="north-east"
  133.  
  134. D$(6)="south-east"
  135.  
  136. D$(7)="north-west"
  137.  
  138. D$(8)="south-west"
  139.  
  140. D$(8)="up"
  141.  
  142. D$(9)="down"
  143.  
  144. DD$(1)="n" : DD$(2)="s" : DD$(3)="e" : DD$(4)="w"
  145.  
  146. DD$(5)="ne" : DD$(6)="se" : DD$(7)="nw" : DD$(8)="sw"
  147.  
  148. DD$(9)="up" : DD$(10)="down"
  149.  
  150. RD$(1)="Starting point"+CD$+CD$+"Not a lot to say about this room, really."
  151.  
  152. RD$(1)=RD$(1)+CD$+"Pretty bare as far as these things go."
  153.  
  154. RD$(2)="The other room"+CD$+CD$+"This room isn't much more exciting, I'm afraid."+CD$
  155.  
  156. RD$(2)=RD$(2)+"You'll really have to wait until the game is finished."
  157.  
  158. OB$(0,0)="knife"
  159.  
  160. OB$(0,1)="A razor sharp kitchen knife."
  161.  
  162. OB$(1,0)="egg"
  163.  
  164. OB$(1,1)="A regular, common or garden, ordinary hen's egg."
  165.  
  166. OB$(2,0)="box"
  167.  
  168. OB$(2,1)="This box is too small to contain anything.  (Actually I just haven't got"+CD$
  169.  
  170. OB$(2,1)=OB$(2,1)+"round to implementing that yet. :)"
  171.  
  172. OB$(3,0)="sock"
  173.  
  174. OB$(3,1)="Pheew!  That STINKS!"
  175.  
  176. OB(0,0)=1
  177.  
  178. OB(1,0)=1
  179.  
  180. OB(2,0)=1
  181.  
  182. OB(3,0)=2
  183.  
  184. RM(1,0)=3
  185.  
  186. RM(1,1)=2
  187.  
  188. RM(2,2)=1
  189.  
  190. RM(2,0)=1
  191.  
  192.  
  193.  
  194. Q$=""
  195.  
  196. SROOM[CURRM]
  197.  
  198. Do 
  199.  
  200.    SUCC=False
  201.  
  202.    CMD[Q$]
  203.  
  204.    Q$=Param$
  205.  
  206.    BRKSENTENCE[Q$]
  207.  
  208.    CM$=W$(1)
  209.  
  210.    If CM$="look"
  211.  
  212.       Print 
  213.  
  214.       SROOM[CURRM]
  215.  
  216.       SUCC=True
  217.  
  218.    End If 
  219.  
  220.    If CM$="quit"
  221.  
  222.       Edit 
  223.  
  224.    End If 
  225.  
  226.    For QQ=1 To 10
  227.  
  228.       If CM$=DD$(QQ)
  229.  
  230.          SUCC=True
  231.  
  232.          If RM(CURRM,QQ)>0
  233.  
  234.             CURRM=RM(CURRM,QQ)
  235.  
  236.             Print 
  237.  
  238.             SROOM[CURRM]
  239.  
  240.          Else 
  241.  
  242.             Print "You can't go that way!"
  243.  
  244.          End If 
  245.  
  246.       End If 
  247.  
  248.    Next 
  249.  
  250.    If CM$="time"
  251.  
  252.       SUCC=True
  253.  
  254.       TME
  255.  
  256.    End If
  257.  
  258.    If CM$="get" or CM$="take"
  259.  
  260.       SUCC=True
  261.  
  262.       TAKE
  263.  
  264.    End If 
  265.  
  266.    If CM$="drop"
  267.  
  268.       SUCC=True
  269.  
  270.       DROP
  271.  
  272.    End If 
  273.  
  274.    If CM$="inv" or CM$="inventory"
  275.  
  276.       SUCC=True
  277.  
  278.       INV
  279.  
  280.    End If 
  281.  
  282.    If CM$="exam" or CM$="examine"
  283.  
  284.       SUCC=True
  285.  
  286.       EXAMINE
  287.  
  288.    End If 
  289.  
  290.    If CM$="help"
  291.  
  292.       SUCC=True
  293.  
  294.       HELP
  295.  
  296.    End If 
  297.  
  298.    If CM$="wait"
  299.  
  300.       SUCC=True
  301.  
  302.       Print "Time passes..."
  303.  
  304.    End If
  305.  
  306.    
  307.  
  308.    If Not SUCC
  309.  
  310.       Print "I don't know how to ";CM$;"."
  311.  
  312.    Else
  313.  
  314.       Inc TM
  315.  
  316.    End If 
  317.  
  318.    
  319.  
  320. Loop
  321.  
  322.  
  323.  
  324. ' *** Procedures *** 
  325.  
  326.  
  327.  
  328. Procedure BRKSENTENCE[A$]
  329.  
  330.    
  331.  
  332.    T$=Lower$((A$-".")-",")
  333.  
  334.    
  335.  
  336.    For J=1 To NW
  337.  
  338.       If Instr(T$," ")=0
  339.  
  340.          If Not SW
  341.  
  342.             W$(J)=T$
  343.  
  344.             SW=True
  345.  
  346.          Else 
  347.  
  348.             W$(J)="###"
  349.  
  350.          End If 
  351.  
  352.       Else 
  353.  
  354.          If Not SW
  355.  
  356.             I=Instr(T$," ")
  357.  
  358.             W$(J)=Left$(T$,I-1)
  359.  
  360.             T$=Right$(T$,(Len(T$)-I))
  361.  
  362.          End If 
  363.  
  364.       End If 
  365.  
  366.    Next 
  367.  
  368.    
  369.  
  370. End Proc
  371.  
  372. Procedure DUMP
  373.  
  374.    
  375.  
  376.    For J=1 To NW
  377.  
  378.       Print W$(J);"  ";
  379.  
  380.    Next 
  381.  
  382.    
  383.  
  384. End Proc
  385.  
  386. Procedure SROOM[N]
  387.  
  388.    
  389.  
  390.    Print RD$(N)
  391.  
  392.    Print 
  393.  
  394.    If RM(CURRM,NUMOB)>0
  395.  
  396.       Print "You see";
  397.  
  398.       Q=RM(N,NUMOB)
  399.  
  400.       V=Q
  401.  
  402.       For R=0 To 256
  403.  
  404.          If OB(R,0)=N
  405.  
  406.             If Q<>V and Q>1
  407.  
  408.                Print ",";
  409.  
  410.             End If 
  411.  
  412.             If Q>1
  413.  
  414.                Print " a";
  415.  
  416.             Else 
  417.  
  418.                If Q<>V
  419.  
  420.                 Print " and a";
  421.  
  422.                Else 
  423.  
  424.                   Print " a";
  425.  
  426.                End If 
  427.  
  428.             End If 
  429.  
  430.             Q=Q-1
  431.  
  432.             O$=OB$(R,NAMEO)
  433.  
  434.             If Instr("aeiouAEIOU",Left$(O$,1))<>0
  435.  
  436.                Print "n ";
  437.  
  438.             Else 
  439.  
  440.                Print " ";
  441.  
  442.             End If 
  443.  
  444.             Print O$;
  445.  
  446.          End If 
  447.  
  448.       Next 
  449.  
  450.       Print "."
  451.  
  452.    End If 
  453.  
  454.    
  455.  
  456.    Print 
  457.  
  458.    Print "Exits :";
  459.  
  460.    For Q=1 To 10
  461.  
  462.       If RM(N,Q)>0
  463.  
  464.          EX=True
  465.  
  466.          Print " ";D$(Q);
  467.  
  468.       End If 
  469.  
  470.    Next Q
  471.  
  472.    If Not EX
  473.  
  474.       Print " None!  Contact the author and quote error : $400";
  475.  
  476.       Print Str$(N)-" ";
  477.  
  478.    End If 
  479.  
  480.    Print "."
  481.  
  482.    
  483.  
  484. End Proc
  485.  
  486. Procedure CMD[L$]
  487.  
  488.    
  489.  
  490.    C$=""
  491.  
  492.    While C$=""
  493.  
  494.       Print 
  495.  
  496.       Input "> ";C$
  497.  
  498.       If C$=""
  499.  
  500.          Print "Huh?"
  501.  
  502.       End If 
  503.  
  504.    Wend 
  505.  
  506.    If Lower$(C$)="again"
  507.  
  508.       C$=L$
  509.  
  510.    End If 
  511.  
  512.    
  513.  
  514. End Proc[C$]
  515.  
  516. Procedure TAKE
  517.  
  518.    
  519.  
  520.    If W$(2)="all"
  521.  
  522.       
  523.  
  524.       If RM(CURRM,NUMOB)>0
  525.  
  526.          FRST=True
  527.  
  528.          For OO=0 To 256
  529.  
  530.             If OB(OO,OBRM)=CURRM
  531.  
  532.                OB(OO,OBRM)=0
  533.  
  534.                If FRST
  535.  
  536.                   Print Upper$(Left$(OB$(OO,0),1));
  537.  
  538.                   Print Right$(OB$(OO,0),Len(OB$(OO,0))-1);
  539.  
  540.                   FRST=False
  541.  
  542.                Else 
  543.  
  544.                   Print ", ";OB$(OO,0);
  545.  
  546.                End If 
  547.  
  548.             End If 
  549.  
  550.          Next 
  551.  
  552.          RM(CURRM,NUMOB)=0
  553.  
  554.          Print " taken."
  555.  
  556.       Else 
  557.  
  558.          Print "Nothing to take!"
  559.  
  560.       End If 
  561.  
  562.       
  563.  
  564.    Else If W$(2)="###"
  565.  
  566.       
  567.  
  568.       Print "Take what?"
  569.  
  570.       
  571.  
  572.    Else 
  573.  
  574.       FRST=True
  575.  
  576.       AFO=False
  577.  
  578.       For QQ=2 To NW
  579.  
  580.          CO$=W$(QQ)
  581.  
  582.          If CO$<>"###" and CO$<>"the" and CO$<>"and"
  583.  
  584.             FO=False
  585.  
  586.             For OO=0 To 256
  587.  
  588.                If OB$(OO,0)=CO$
  589.  
  590.                   If OB(OO,OBRM)=CURRM
  591.  
  592.                      OB(OO,OBRM)=0
  593.  
  594.                      RM(CURRM,NUMOB)=RM(CURRM,NUMOB)-1
  595.  
  596.                      FO=True
  597.  
  598.                      AFO=True
  599.  
  600.                      If FRST
  601.  
  602.                         Print Upper$(Left$(CO$,1));
  603.  
  604.                         Print Right$(CO$,Len(CO$)-1);
  605.  
  606.                         FRST=False
  607.  
  608.                      Else 
  609.  
  610.                         Print ", ";OB$(OO,0);
  611.  
  612.                      End If 
  613.  
  614.                   End If 
  615.  
  616.                End If 
  617.  
  618.             Next 
  619.  
  620.             If Not FO
  621.  
  622.                If AFO
  623.  
  624.                   Print " taken, but you don't see any ";CO$"."
  625.  
  626.                Else
  627.  
  628.                   Print "You don't see any ";CO$;"."
  629.  
  630.                End If
  631.  
  632.                FO=False
  633.  
  634.                AFO=False
  635.  
  636.                FRST=True
  637.  
  638.             End If
  639.  
  640.          End If 
  641.  
  642.       Next 
  643.  
  644.       If FO
  645.  
  646.          Print " taken."
  647.  
  648.       End If
  649.  
  650.    End If 
  651.  
  652. End Proc
  653.  
  654. Procedure DROP
  655.  
  656.    
  657.  
  658.    FRST=True
  659.  
  660.    DR=False
  661.  
  662.    If W$(2)="all"
  663.  
  664.       
  665.  
  666.       For OO=0 To 256
  667.  
  668.          If OB(OO,OBRM)=0
  669.  
  670.             OB(OO,OBRM)=CURRM
  671.  
  672.             If FRST
  673.  
  674.                Print Upper$(Left$(OB$(OO,0),1));
  675.  
  676.                Print Right$(OB$(OO,0),Len(OB$(OO,0))-1);
  677.  
  678.                FRST=False
  679.  
  680.             Else 
  681.  
  682.                Print ", ";OB$(OO,0);
  683.  
  684.             End If 
  685.  
  686.             DR=True
  687.  
  688.          End If 
  689.  
  690.       Next 
  691.  
  692.       OC=0
  693.  
  694.       For OO=0 To 256
  695.  
  696.          If OB(OO,0)=CURRM
  697.  
  698.             Inc OC
  699.  
  700.          End If 
  701.  
  702.       Next 
  703.  
  704.       RM(CURRM,NUMOB)=OC
  705.  
  706.       
  707.  
  708.       
  709.  
  710.       If Not DR
  711.  
  712.          Print "Nothing to drop!"
  713.  
  714.       Else 
  715.  
  716.          Print " dropped."
  717.  
  718.       End If 
  719.  
  720.       
  721.  
  722.    Else If W$(2)="###"
  723.  
  724.       
  725.  
  726.       Print "Drop what?"
  727.  
  728.       
  729.  
  730.    Else 
  731.  
  732.       FRST=True
  733.  
  734.       ADR=False
  735.  
  736.       For QQ=2 To NW
  737.  
  738.          CO$=W$(QQ)
  739.  
  740.          If CO$<>"###" and CO$<>"the" and CO$<>"and"
  741.  
  742.             DR=False
  743.  
  744.             For OO=0 To 256
  745.  
  746.                If OB$(OO,0)=CO$
  747.  
  748.                   If OB(OO,OBRM)=0
  749.  
  750.                      OB(OO,OBRM)=CURRM
  751.  
  752.                      RM(CURRM,NUMOB)=RM(CURRM,NUMOB)+1
  753.  
  754.                      DR=True
  755.  
  756.                      ADR=True
  757.  
  758.                      If FRST
  759.  
  760.                         Print Upper$(Left$(OB$(OO,0),1));
  761.  
  762.                         Print Right$(OB$(OO,0),Len(OB$(OO,0))-1);
  763.  
  764.                         FRST=False
  765.  
  766.                      Else 
  767.  
  768.                         Print ", ";OB$(OO,0);
  769.  
  770.                      End If 
  771.  
  772.                      
  773.  
  774.                   End If 
  775.  
  776.                End If 
  777.  
  778.             Next 
  779.  
  780.             If Not DR
  781.  
  782.                If ADR
  783.  
  784.                   Print " dropped, but don't have a ";CO$;"."
  785.  
  786.                Else 
  787.  
  788.                   Print "You don't have a ";CO$;"."
  789.  
  790.                End If 
  791.  
  792.                DR=False
  793.  
  794.                ADR=False
  795.  
  796.                FRST=True
  797.  
  798.             End If 
  799.  
  800.          End If 
  801.  
  802.       Next 
  803.  
  804.       If DR
  805.  
  806.          Print " dropped."
  807.  
  808.       End If 
  809.  
  810.    End If 
  811.  
  812.    
  813.  
  814. End Proc
  815.  
  816. Procedure INV
  817.  
  818.    
  819.  
  820.    CAR=False
  821.  
  822.    Print "You are carrying :"
  823.  
  824.    For OO=0 To 256
  825.  
  826.       If OB(OO,OBRM)=0
  827.  
  828.          Print "  ";OB$(OO,0)
  829.  
  830.          CAR=True
  831.  
  832.       End If 
  833.  
  834.    Next 
  835.  
  836.    If Not CAR
  837.  
  838.       Print "  nothing."
  839.  
  840.    End If 
  841.  
  842.    
  843.  
  844. End Proc
  845.  
  846. Procedure EXAMINE
  847.  
  848.    
  849.  
  850.    If W$(2)="###"
  851.  
  852.       
  853.  
  854.       Print "Examine what?"
  855.  
  856.       
  857.  
  858.    Else 
  859.  
  860.       
  861.  
  862.       For OO=0 To 256
  863.  
  864.          
  865.  
  866.          If OB$(OO,0)=W$(2)
  867.  
  868.             
  869.  
  870.             If OB(OO,OBRM)=CURRM
  871.  
  872.                Print "You'll need to pick it up first!"
  873.  
  874.                EX=True
  875.  
  876.             End If 
  877.  
  878.             
  879.  
  880.             If OB(OO,OBRM)=0
  881.  
  882.                EX=True
  883.  
  884.                Print OB$(OO,1)
  885.  
  886.             End If 
  887.  
  888.             
  889.  
  890.          End If 
  891.  
  892.          
  893.  
  894.       Next 
  895.  
  896.       
  897.  
  898.       If Not EX
  899.  
  900.          Print "No ";W$(2);" to examine!"
  901.  
  902.       End If 
  903.  
  904.       
  905.  
  906.    End If 
  907.  
  908.    
  909.  
  910.    
  911.  
  912.    
  913.  
  914. End Proc
  915.  
  916. Procedure HELP
  917.  
  918.    
  919.  
  920.    Print "Hah!  You must be kidding!  Work it out yourself."
  921.  
  922.    
  923.  
  924. End Proc
  925.  
  926. Procedure TME
  927.  
  928.  
  929.  
  930.    Print "It's";(TM div 60);":";
  931.  
  932.    QQQ$=Str$((TM Mod 60))-" "
  933.  
  934.    Print QQQ$;" since you started."
  935.  
  936.  
  937.  
  938. End Proc
  939.  
  940.  
  941. --
  942. GCS -d+ H+ s++:- g+ p? !au a- w+++            !Productions 1995
  943. v* C+++ UB+++A++++ P++ L++ E+ N+++       http://satelnet.org/~mentat/
  944. K+ !W--- M-- V po- Y+ t++ 5+ jx G?
  945. R tv++ D- B--- e+ u** h f r++ !n y+ "No matter where you go, there you are."
  946.  
  947.  
  948.  
  949.